package com.briup.cart.controller;

import com.briup.cart.domain.vo.CollectGetListVO;
import com.briup.cart.service.CollectService;
import com.briup.common.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collects")
public class CollectController {

    @Autowired
    private CollectService collectService;

    /**
     * 判断当前用户是否收藏某商品
     */
    @GetMapping("/{goodsId}")
    public Result<Boolean> isCollect(@PathVariable Integer goodsId){
        Boolean flag = collectService.isCollect(goodsId);
        return Result.success(flag);
    }


    /**
     * 取消收藏
     */
    @PutMapping("/remove/{goodsId}")
    public Result remove(@PathVariable Integer goodsId){
        collectService.remove(goodsId);
        return Result.success();
    }

    /**
     * 添加收藏
     */
    @PutMapping("/add/{goodsId}")
    public Result add(@PathVariable Integer goodsId){
        collectService.add(goodsId);
        return Result.success();
    }


    /**
     * 获取当前登录用户的收藏列表信息
     */
    @GetMapping
    public Result<List<CollectGetListVO>> getCollectList(){
        List<CollectGetListVO> collectList = collectService.getCollectList();
        return Result.success(collectList);
    }


    /**
     * 单个删除与批量删除收藏信息
     */
    @DeleteMapping
    public Result batchDelete(@RequestBody List<Integer> ids){
        collectService.batchDelete(ids);
        return Result.success();
    }


}
